/**
*      author: Y_Yao
*      created: 2025-04-27 20:24:10
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 9e18;
const int INF = 0x3f3f3f3f;
map<int,int> mp;
const int N = 2e5 + 7;
int a[N];
int n,d;
bool vis[N];

void solve()
{
    cin >> n >> d;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
        mp[a[i]]++;
    }

    int ans = 0;
    vector<int> tmp;
    vector<int> f,g;
    for(auto& e : mp)
    {
        if(vis[e.first]) continue;
        tmp.clear();
        g.clear();
        f.clear();
        f.push_back(0);
        g.push_back(0);
        tmp.push_back(0);
        tmp.push_back(e.first);
        int cur = e.first + d;
        while(mp.count(cur))
        {
            vis[cur] = true;
            tmp.push_back(cur);
            cur = cur + d;
        }
        if(tmp.size() == 2) continue;
        for(int i = 1;i <= tmp.size() - 1;i++)
        {
            f.push_back(min(f[i-1],g[i-1]) + mp[tmp[i]]);
            g.push_back(f[i-1]);
        }
        ans += min(f[tmp.size() - 1],g[tmp.size() - 1]);
    }
    cout << ans << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    // cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}